# -*- coding: utf-8 -*-
import xlrd
import xlwt
import random

def read_excel():
    workbook = xlrd.open_workbook(r'demo.xls')
    print (workbook.sheet_names())  # [u'sheet1', u'sheet2']
    sheet2 = workbook.sheet_by_index(0)  # sheet索引从0开始
    print (sheet2.name, sheet2.nrows, sheet2.ncols)
    cols = sheet2.col_values(0)
    return cols

def write_excel(data):
    f = xlwt.Workbook() #创建工作簿
    sheet1 = f.add_sheet(u'sheet1', cell_overwrite_ok=True)  # 创建sheet
    number = len(data)
    number=int(number/10)
    print(number)
    for i in range(0, number+1):
        for x in range(0,10):
            if i*10+x<len(data):
                sheet1.write(x, i, data[i*10+x])
    f.save('demo1.xls')

if __name__ == '__main__':
    number=list()
    cols = read_excel()
    element=list()
    size=len(cols)
    while len(number)<size:
        r=random.randint(0,size-1)
        if r not in number:
            number.append(r)
    for x in number:
        element.append(cols[x])
    print(number)
    print(element)
    write_excel(element)

